/**
 * 
 */
package neptune.web.client.view.components.editor;

import neptune.web.client.model.topology.SerializableLink;
import neptune.web.client.model.topology.SerializableTopology;

import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.TreeItem;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class LinkMenuBar extends MenuBar {

	private MenuItem rootItem;
	private final SerializableLink link;

	public LinkMenuBar(SerializableLink link, SerializableTopology topology,
			TreeItem treeItem, TopologyEditor editor) {
		super(false);
		this.link = link;

		MenuItem props = new MenuItem("Properties", new LinkPropsCommand(link,
				topology, treeItem, editor));
		MenuItem removeNode = new MenuItem("Remove", new RemoveLinkCommand(
				link, topology, treeItem, editor));

		MenuBar options = new MenuBar(true);

		options.addItem(props);
		options.addItem(removeNode);

		rootItem = new MenuItem(link.getId(), options);
		addItem(rootItem);
		setText(link.getId());

		options.setStylePrimaryName("TopologyEditor-tree-NodeItem");
		this.setStylePrimaryName("TopologyEditor-tree-RootNodeItem");
	}

	/**
	 * @return the rootItem
	 */
	public MenuItem getRootItem() {
		return rootItem;
	}

	public void setText(String text) {
		if (link.getSource() == null || link.getDestination() == null)
			rootItem.setText(text);
		else
			rootItem.setText(text + " [" + link.getSource().getNodeId() + " - "
					+ link.getDestination().getNodeId() + "]");
	}

}
